package com.yueya.business.file.service;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.yueya.business.file.model.WFile;

public class WFileService {
	
	
	public WFile getWFile(String rec_id,String file_type){
		
		String sql ="select * from w_file where rec_id =? and file_type=?";
		WFile wfile = WFile.dao.findFirst(sql, rec_id,file_type);
		return wfile;
	}
	
	public List<WFile> getList(String rec_id,String file_type){
		String sql ="select * from w_file where rec_id =? and file_type=?  order by sort_id ";
		List<WFile> list = WFile.dao.find(sql,rec_id,file_type);
		return list;
	}
	
	public int updateWFile(String rec_id ,String id){
		
		String sql="update w_file set rec_id =? where id=? ";
		return Db.update(sql, rec_id,id);
		
	}
	
	public int deleteWFile(String id){
		String sql="delete from w_file  where id=? ";
		return Db.update(sql,id);
	}
	
	public int getOrderId(){
		String sql ="select Max(sort_id) mx  from w_file ";
		WFile wfile = WFile.dao.findFirst(sql);
		return wfile.getInt("mx")+1;
	}
	
	
	public void bathUpdate(String rec_id ,String[] ids){
		for(int i =0 ;i<ids.length;i++ ){
			updateWFile(rec_id,ids[i]);
		}
	}
	
	public void bathDetele(String[] ids){
		for(int i =0 ;i<ids.length;i++ ){
			deleteWFile(ids[i]);
		}
	}

}
